package org.zjx.analysis.window;

import lombok.Getter;
import org.zjx.analysis.BaseAnalysis;
import org.zjx.core.IWindow;
import org.zjx.entity.ParagraphBean;
import org.zjx.enums.FontType;
import org.zjx.util.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Collections;
import java.util.List;

public class NpcDialogueAnalysis extends BaseAnalysis {
    @Getter
    private List<ParagraphBean.Word> wordList;

    public NpcDialogueAnalysis(IWindow window, BufferedImage screenshot) {
        super(window, screenshot);
    }

    @Override
    protected void analysis() {
        wordList = window.execute(op -> op.identifyFont(window, screenshot,
                conversion(windowArea,getContentArea()), Collections.singletonList(new Color(238, 0, 0)), FontType.NPC, 14, false));
    }

    public Rectangle getButtonArea(String text){
        if (!isOpened() || wordList == null) throw new IllegalArgumentException("对话栏不存在!!!");
        for (ParagraphBean.Word word : wordList) {
            if (word.getName().equals(text)) {
                return word.getRectangle();
            }
        }
        return null;
    }

    @Override
    protected void initResources() {

    }

    public Rectangle getContentArea() {
        return ImageUtil.createRect(11,36,501,183);
    }

    @Override
    public Rectangle closeArea() {
        return ImageUtil.createRect(524, 33, 539, 48);
    }

    @Override
    public Rectangle getOriginBounds() {
        return ImageUtil.createRect(134, 261, 675, 463);
    }

    @Override
    public Rectangle getRefImageArea() {
        return ImageUtil.createRect(506, 170, 521, 184);
    }

    @Override
    public BufferedImage getRefImage() {
        return ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAABAAAAAPCAYAAADtc08vAAAA40lEQVR4Xm1SqxXDMAz0/hMUBgZ2iICCgoACw8BukUbSnXxyA/T8LOk+kt36ez37tpwHzv5a6rk94rS65SQM0/xiRRIYAOBjB2gCa94JUh3KfieA6lNYTzgA0FlZ+DyhGkRsTkJxEyN4DFVaTKtlJ7xHLUbYh4Krl5yMo4H+GIH2EqChwPVmBBC4IvagAHWXISTYAdTUSTqrhOpk/AMW+GnUpqjf7aRVywGO7Ud+fj67f69FM99KY7EeznIv6Qo54MY/mOc3UjaWsWSpsYPBNs9XXoAEWB5HlZ9Yg8/694RWk9wP00IQsvCQR7oAAAAASUVORK5CYII=");
    }
}
